Imports Iou = System.IO
Imports Log = Enhancements.Core.Logging
Imports Reg = System.Text.RegularExpressions
Imports Sys = System
Imports Tex = System.Text
Imports Xsd = System.Xml.Schema
Imports W3c = System.Xml

Namespace Enhancements.Core
    <DebuggerStepThrough()> _
        Friend NotInheritable Class ___Assert

        Private Sub New()
        End Sub

        Friend Shared Function ___IsNull(ByVal _objectName As System.String, ByVal _object As Sys.Object, ByVal _throwException As System.Boolean) As System.Boolean
            Dim _returnValue As System.Boolean = _object Is Nothing

            If Not _returnValue And _throwException Then
                Throw New IsNullNotException(_objectName, _object)
            End If

            Return _returnValue
        End Function

        Friend Shared Function ___IsNullNot(ByVal _objectName As System.String, ByVal _object As Sys.Object, ByVal _throwException As System.Boolean) As System.Boolean
            Dim _returnValue As System.Boolean = Not _object Is Nothing

            If Not _returnValue And _throwException Then
                Throw New IsNullException(_objectName)
            End If

            Return _returnValue
        End Function

        Friend Shared Function ___IsEmpty(ByVal _objectName As System.String, ByVal _object As System.String, ByVal _throwException As System.Boolean) As System.Boolean
            ___IsNullNot(_objectName, _object, True)

            Dim _returnValue As System.Boolean = Sys.String.Equals(_object, Sys.String.Empty, StringComparison.OrdinalIgnoreCase)

            If Not _returnValue And _throwException Then
                Throw New IsEmptyNotException(_objectName)
            End If

            Return _returnValue
        End Function

        Friend Shared Function ___IsEmptyNot(ByVal _objectName As System.String, ByVal _object As System.String, ByVal _throwException As System.Boolean) As System.Boolean
            ___IsNullNot(_objectName, _object, True)

            Dim _returnValue As System.Boolean = Not Sys.String.Equals(_object, Sys.String.Empty, StringComparison.OrdinalIgnoreCase)

            If Not _returnValue And _throwException Then
                Throw New IsEmptyException(_objectName)
            End If

            Return _returnValue
        End Function

        Friend Shared Function ___IsEmpty(ByVal _objectName As System.String, ByVal _object As System.Guid, ByVal _throwException As System.Boolean) As System.Boolean
            Dim _returnValue As System.Boolean = Sys.Guid.Equals(_object, Sys.Guid.Empty)

            If Not _returnValue And _throwException Then
                Throw New IsEmptyNotException(_objectName)
            End If

            Return _returnValue
        End Function

        Friend Shared Function ___IsEmptyNot(ByVal _objectName As System.String, ByVal _object As System.Guid, ByVal _throwException As System.Boolean) As System.Boolean
            Dim _returnValue As System.Boolean = Not Sys.Guid.Equals(_object, Sys.Guid.Empty)

            If Not _returnValue And _throwException Then
                Throw New IsEmptyException(_objectName)
            End If

            Return _returnValue
        End Function

        Friend Shared Function ___IsUnicodeWhiteSpace(ByVal _objectName As System.String, ByVal _object As System.Char, ByVal _throwException As System.Boolean) As System.Boolean
            Dim _returnValue As System.Boolean = System.Char.IsWhiteSpace(_object)

            If Not _returnValue And _throwException Then
                Throw New IsUnicodeWhiteSpaceNotException(_objectName, _object)
            End If

            Return _returnValue
        End Function

        Friend Shared Function ___IsUnicodeWhiteSpaceNot(ByVal _objectName As System.String, ByVal _object As System.Char, ByVal _throwException As System.Boolean) As System.Boolean
            Dim _returnValue As System.Boolean = Not System.Char.IsWhiteSpace(_object)

            If Not _returnValue And _throwException Then
                Throw New IsUnicodeWhiteSpaceException(_objectName, _object)
            End If

            Return _returnValue
        End Function

        Friend Shared Function ___IsOfType(ByVal _objectName As System.String, ByVal _object As System.Object, ByVal _objectType As Sys.Type, ByVal _throwException As System.Boolean) As System.Boolean
            ___IsNullNot("_object", _object, True)
            ___IsNullNot("_objectType", _objectType, True)

            Dim _returnValue As System.Boolean = _object.GetType() Is _objectType

            If Not _returnValue And _throwException Then
                Throw New IsOfTypeNotException(_objectName, _object, _objectType)
            End If

            Return _returnValue
        End Function

        Friend Shared Function ___IsOfTypeNot(ByVal _objectName As System.String, ByVal _object As System.Object, ByVal _objectType As Sys.Type, ByVal _throwException As System.Boolean) As System.Boolean
            ___IsNullNot("_object", _object, True)
            ___IsNullNot("_objectType", _objectType, True)

            Dim _returnValue As System.Boolean = Not _object.GetType() Is _objectType

            If Not _returnValue And _throwException Then
                Throw New IsOfTypeException(_objectName, _object, _objectType)
            End If

            Return _returnValue
        End Function

        Friend Shared Function ___IsOfType(ByVal _objectName As System.String, ByVal _object As System.Object, ByVal _objectTypeArray() As Sys.Type, ByVal _throwException As System.Boolean) As System.Boolean
            ___IsNullNot("_object", _object, True)
            ___IsNullNot("_objectTypeArray", _objectTypeArray, True)

            Dim _returnValue As System.Boolean = False
            For Each _objectTypeArrayItem As System.Type In _objectTypeArray
                If ___IsNullNot("_objectTypeArrayItem", _objectTypeArrayItem, False) Then
                    If _object.GetType() Is _objectTypeArrayItem Then
                        _returnValue = True
                        Exit For
                    End If
                End If
            Next _objectTypeArrayItem

            If Not _returnValue And _throwException Then
                Throw New IsOfTypeNotException(_objectName, _object, _objectTypeArray)
            End If

            Return _returnValue
        End Function

        Friend Shared Function ___IsOfTypeNot(ByVal _objectName As System.String, ByVal _object As System.Object, ByVal _objectTypeArray() As Sys.Type, ByVal _throwException As System.Boolean) As System.Boolean
            ___IsNullNot("_object", _object, True)
            ___IsNullNot("_objectTypeArray", _objectTypeArray, True)

            Dim _returnValue As System.Boolean = True
            For Each _objectTypeArrayItem As System.Type In _objectTypeArray
                If ___IsNullNot("_objectTypeArrayItem", _objectTypeArrayItem, False) Then
                    If _object.GetType() Is _objectTypeArrayItem Then
                        _returnValue = False
                        Exit For
                    End If
                End If
            Next _objectTypeArrayItem

            If Not _returnValue And _throwException Then
                Throw New IsOfTypeException(_objectName, _object, _objectTypeArray)
            End If

            Return _returnValue
        End Function

        Friend Shared Function ___IsInRange(ByVal _objectName As System.String, ByVal _object As System.Int64, ByVal _objectMinimum As Sys.Int64, ByVal _objectMaximum As Sys.Int64, ByVal _throwException As System.Boolean) As System.Boolean
            Dim _returnValue As System.Boolean = _object >= _objectMinimum And _object <= _objectMaximum

            If Not _returnValue And _throwException Then
                Throw New IsInRangeNotException(_objectName, _object, _objectMinimum, _objectMaximum)
            End If

            Return _returnValue
        End Function

        Friend Shared Function ___IsInRangeNot(ByVal _objectName As System.String, ByVal _object As System.Int64, ByVal _objectMinimum As Sys.Int64, ByVal _objectMaximum As Sys.Int64, ByVal _throwException As System.Boolean) As System.Boolean
            Dim _returnValue As System.Boolean = Not (_object >= _objectMinimum And _object <= _objectMaximum)

            If Not _returnValue And _throwException Then
                Throw New IsInRangeException(_objectName, _object, _objectMinimum, _objectMaximum)
            End If

            Return _returnValue
        End Function

        Friend Shared Function ___IsEqual(ByVal _objectName As System.String, ByVal _object As System.String, ByVal _object2Name As System.String, ByVal _object2 As System.String, ByVal _throwException As System.Boolean) As System.Boolean
            ___IsNullNot(_objectName, _object, True)
            ___IsNullNot(_object2Name, _object2, True)

            Dim _returnValue As System.Boolean = Sys.String.Equals(_object, _object2, StringComparison.Ordinal)

            If Not _returnValue And _throwException Then
                Throw New IsEqualNotException(_objectName, _object, _object2Name, _object2)
            End If

            Return _returnValue
        End Function

        Friend Shared Function ___IsEqualNot(ByVal _objectName As System.String, ByVal _object As System.String, ByVal _object2Name As System.String, ByVal _object2 As System.String, ByVal _throwException As System.Boolean) As System.Boolean
            ___IsNullNot(_objectName, _object, True)
            ___IsNullNot(_object2Name, _object2, True)

            Dim _returnValue As System.Boolean = Not Sys.String.Equals(_object, _object2, StringComparison.Ordinal)

            If Not _returnValue And _throwException Then
                Throw New IsEqualException(_objectName, _object, _object2Name, _object2)
            End If

            Return _returnValue
        End Function

        Friend Shared Function ___Is(ByVal _objectName As System.String, ByVal _object As Sys.Object, ByVal _object2Name As System.String, ByVal _object2 As Sys.Object, ByVal _throwException As System.Boolean) As System.Boolean
            ___IsNullNot(_objectName, _object, True)
            ___IsNullNot(_object2Name, _object2, True)

            Dim _returnValue As System.Boolean = Sys.Object.ReferenceEquals(_object, _object2)

            If Not _returnValue And _throwException Then
                Throw New IsNotException(_objectName, _object, _object2Name, _object2)
            End If

            Return _returnValue
        End Function

        Friend Shared Function ___IsNot(ByVal _objectName As System.String, ByVal _object As Sys.Object, ByVal _object2Name As System.String, ByVal _object2 As Sys.Object, ByVal _throwException As System.Boolean) As System.Boolean
            ___IsNullNot(_objectName, _object, True)
            ___IsNullNot(_object2Name, _object2, True)

            Dim _returnValue As System.Boolean = Not Sys.Object.ReferenceEquals(_object, _object2)

            If Not _returnValue And _throwException Then
                Throw New IsException(_objectName, _object, _object2Name, _object2)
            End If

            Return _returnValue
        End Function

        Friend Shared Function ___IsTrue(ByVal _objectName As System.String, ByVal _object As System.Boolean, ByVal _throwException As System.Boolean) As System.Boolean
            Dim _returnValue As System.Boolean = _object

            If Not _returnValue And _throwException Then
                Throw New IsTrueNotException(_objectName)
            End If

            Return _returnValue
        End Function

        Friend Shared Function ___IsTrueNot(ByVal _objectName As System.String, ByVal _object As System.Boolean, ByVal _throwException As System.Boolean) As System.Boolean
            Dim _returnValue As System.Boolean = Not _object

            If Not _returnValue And _throwException Then
                Throw New IsTrueException(_objectName)
            End If

            Return _returnValue
        End Function

        Friend Shared Function ___IsPathValid(ByVal _objectName As System.String, ByVal _object As System.String, ByVal _throwException As System.Boolean) As System.Boolean
            ___IsNullNot(_objectName, _object, True)

            Dim _returnValue As System.Boolean = _object.IndexOfAny(Iou.Path.GetInvalidPathChars()) = -1

            If Not _returnValue And _throwException Then
                Throw New IsPathValidNotException(_objectName, _object)
            End If

            Return _returnValue
        End Function

        Friend Shared Function ___IsPathValidNot(ByVal _objectName As System.String, ByVal _object As System.String, ByVal _throwException As System.Boolean) As System.Boolean
            ___IsNullNot(_objectName, _object, True)

            Dim _returnValue As System.Boolean = Not (_object.IndexOfAny(Iou.Path.GetInvalidPathChars()) = -1)

            If Not _returnValue And _throwException Then
                Throw New IsPathValidException(_objectName, _object)
            End If

            Return _returnValue
        End Function

        Friend Shared Function ___IsPathPartValid(ByVal _objectName As System.String, ByVal _object As System.String, ByVal _throwException As System.Boolean) As System.Boolean
            ___IsNullNot(_objectName, _object, True)

            Dim _returnValue As System.Boolean = _object.IndexOfAny(Iou.Path.GetInvalidFileNameChars()) = -1

            If Not _returnValue And _throwException Then
                Throw New IsPathPartValidNotException(_objectName, _object)
            End If

            Return _returnValue
        End Function

        Friend Shared Function ___IsPathPartValidNot(ByVal _objectName As System.String, ByVal _object As System.String, ByVal _throwException As System.Boolean) As System.Boolean
            ___IsNullNot(_objectName, _object, True)

            Dim _returnValue As System.Boolean = Not (_object.IndexOfAny(Iou.Path.GetInvalidFileNameChars()) = -1)

            If Not _returnValue And _throwException Then
                Throw New IsPathPartValidException(_objectName, _object)
            End If

            Return _returnValue
        End Function

        Friend Shared Function ___IsIn(ByVal _objectName As System.String, ByVal _object As System.String, ByVal _objectCharacter As System.Char, ByVal _throwException As System.Boolean) As System.Boolean
            ___IsNullNot(_objectName, _object, True)

            Dim _returnValue As System.Boolean = _object.IndexOf(_objectCharacter) <> -1

            If Not _returnValue And _throwException Then
                Throw New IsInNotException(_objectName, _object, _objectCharacter)
            End If

            Return _returnValue
        End Function

        Friend Shared Function ___IsInNot(ByVal _objectName As System.String, ByVal _object As System.String, ByVal _objectCharacter As System.Char, ByVal _throwException As System.Boolean) As System.Boolean
            ___IsNullNot(_objectName, _object, True)

            Dim _returnValue As System.Boolean = Not (_object.IndexOf(_objectCharacter) <> -1)

            If Not _returnValue And _throwException Then
                Throw New IsInException(_objectName, _object, _objectCharacter)
            End If

            Return _returnValue
        End Function

        Friend Shared Function ___IsIn(ByVal _objectName As System.String, ByVal _object As System.String, ByVal _objectArray() As System.String, ByVal _throwException As System.Boolean) As System.Boolean
            ___IsNullNot(_objectName, _object, True)
            ___IsNullNot("_objectArray", _objectArray, True)

            Dim _returnValue As System.Boolean = False
            For Each _objectArrayItem As System.String In _objectArray
                If ___IsNullNot("_objectArrayItem", _objectArrayItem, False) Then
                    If _object.IndexOf(_objectArrayItem) <> -1 Then
                        _returnValue = True
                        Exit For
                    End If
                End If
            Next _objectArrayItem

            If Not _returnValue And _throwException Then
                Throw New IsInNotException(_objectName, _object, _objectArray)
            End If

            Return _returnValue
        End Function

        Friend Shared Function ___IsInNot(ByVal _objectName As System.String, ByVal _object As System.String, ByVal _objectArray() As System.String, ByVal _throwException As System.Boolean) As System.Boolean
            ___IsNullNot(_objectName, _object, True)
            ___IsNullNot("_objectArray", _objectArray, True)

            Dim _returnValue As System.Boolean = True
            For Each _objectArrayItem As System.String In _objectArray
                If ___IsNullNot("_objectArrayItem", _objectArrayItem, False) Then
                    If _object.IndexOf(_objectArrayItem) <> -1 Then
                        _returnValue = False
                        Exit For
                    End If
                End If
            Next _objectArrayItem

            If Not _returnValue And _throwException Then
                Throw New IsInException(_objectName, _object, _objectArray)
            End If

            Return _returnValue
        End Function

        Friend Shared Function ___IsFolderExistent(ByVal _objectName As System.String, ByVal _object As System.String, ByVal _throwException As System.Boolean) As System.Boolean
            ___IsNullNot(_objectName, _object, True)
            ___IsPathValid(_objectName, _object, True)

            Dim _returnValue As System.Boolean = Iou.Directory.Exists(_object)

            If Not _returnValue And _throwException Then
                Throw New IsFolderExistentNotException(_objectName, _object)
            End If

            Return _returnValue
        End Function

        Friend Shared Function ___IsFolderExistentNot(ByVal _objectName As System.String, ByVal _object As System.String, ByVal _throwException As System.Boolean) As System.Boolean
            ___IsNullNot(_objectName, _object, True)
            ___IsPathValid(_objectName, _object, True)

            Dim _returnValue As System.Boolean = Not Iou.Directory.Exists(_object)

            If Not _returnValue And _throwException Then
                Throw New IsFolderExistentException(_objectName, _object)
            End If

            Return _returnValue
        End Function

        Friend Shared Function ___IsFileExistent(ByVal _objectName As System.String, ByVal _object As System.String, ByVal _throwException As System.Boolean) As System.Boolean
            ___IsNullNot(_objectName, _object, True)
            ___IsPathValid(_objectName, _object, True)

            Dim _returnValue As System.Boolean = Iou.File.Exists(_object)

            If Not _returnValue And _throwException Then
                Throw New IsFileExistentNotException(_objectName, _object)
            End If

            Return _returnValue
        End Function

        Friend Shared Function ___IsFileExistentNot(ByVal _objectName As System.String, ByVal _object As System.String, ByVal _throwException As System.Boolean) As System.Boolean
            ___IsNullNot(_objectName, _object, True)
            ___IsPathValid(_objectName, _object, True)

            Dim _returnValue As System.Boolean = Not Iou.File.Exists(_object)

            If Not _returnValue And _throwException Then
                Throw New IsFileExistentException(_objectName, _object)
            End If

            Return _returnValue
        End Function

        Friend Shared Function ___IsInRegularExpression(ByVal _objectName As System.String, ByVal _object As System.String, ByVal _objectRegularExpression As System.String, ByVal _throwException As System.Boolean) As System.Boolean
            ___IsNullNot(_objectName, _object, True)
            ___IsNullNot("_objectRegularExpression", _objectRegularExpression, True)

            Dim _returnValue As System.Boolean = Reg.Regex.IsMatch(_object, _objectRegularExpression)

            If Not _returnValue And _throwException Then
                Throw New IsInRegularExpressionNotException(_objectName, _object, _objectRegularExpression)
            End If

            Return _returnValue
        End Function

        Friend Shared Function ___IsInRegularExpressionNot(ByVal _objectName As System.String, ByVal _object As System.String, ByVal _objectRegularExpression As System.String, ByVal _throwException As System.Boolean) As System.Boolean
            ___IsNullNot(_objectName, _object, True)
            ___IsNullNot("_objectRegularExpression", _objectRegularExpression, True)

            Dim _returnValue As System.Boolean = Not Reg.Regex.IsMatch(_object, _objectRegularExpression)

            If Not _returnValue And _throwException Then
                Throw New IsInRegularExpressionException(_objectName, _object, _objectRegularExpression)
            End If

            Return _returnValue
        End Function

        Friend Shared Function ___IsDisposed(ByVal _objectName As System.String, ByVal _object As System.Boolean, ByVal _throwException As System.Boolean) As System.Boolean
            Dim _returnValue As System.Boolean = _object

            If Not _returnValue And _throwException Then
                Throw New IsDisposedNotException(_objectName)
            End If

            Return _returnValue
        End Function

        Friend Shared Function ___IsDisposedNot(ByVal _objectName As System.String, ByVal _object As System.Boolean, ByVal _throwException As System.Boolean) As System.Boolean
            Dim _returnValue As System.Boolean = Not _object

            If Not _returnValue And _throwException Then
                Throw New IsDisposedException(_objectName)
            End If

            Return _returnValue
        End Function

        Friend Shared Function ___IsInitialized(ByVal _objectName As System.String, ByVal _object As System.Boolean, ByVal _throwException As System.Boolean) As System.Boolean
            Dim _returnValue As System.Boolean = _object

            If Not _returnValue And _throwException Then
                Throw New IsInitializedNotException(_objectName)
            End If

            Return _returnValue
        End Function

        Friend Shared Function ___IsInitializedNot(ByVal _objectName As System.String, ByVal _object As System.Boolean, ByVal _throwException As System.Boolean) As System.Boolean
            Dim _returnValue As System.Boolean = Not _object

            If Not _returnValue And _throwException Then
                Throw New IsInitializedException(_objectName)
            End If

            Return _returnValue
        End Function

        Friend Shared Function ___IsXmlWellFormed(ByVal _objectName As System.String, ByVal _object() As System.Byte, ByVal _throwException As System.Boolean) As System.Boolean
            ___IsArrayEmptyNot("_object", _object, True)

            Dim _returnValue As System.Boolean = False

            Dim _stream As Iou.MemoryStream = New Iou.MemoryStream(_object)
            Dim _xmlDocument As W3c.XmlDocument = New W3c.XmlDocument()
            Try
                _xmlDocument.Load(_stream)
                _returnValue = True
            Catch
            End Try
            _stream.Dispose()

            If Not _returnValue And _throwException Then
                Throw New IsXmlWellFormedNotException(_objectName, _object)
            End If

            Return _returnValue
        End Function

        Friend Shared Function ___IsXmlWellFormedNot(ByVal _objectName As System.String, ByVal _object() As System.Byte, ByVal _throwException As System.Boolean) As System.Boolean
            ___IsArrayEmptyNot("_object", _object, True)

            Dim _returnValue As System.Boolean = True

            Dim _stream As Iou.MemoryStream = New Iou.MemoryStream(_object)
            Dim _xmlDocument As W3c.XmlDocument = New W3c.XmlDocument()
            Try
                _xmlDocument.Load(_stream)
                _returnValue = False
            Catch
            End Try
            _stream.Dispose()

            If Not _returnValue And _throwException Then
                Throw New IsXmlWellFormedException(_objectName, _object)
            End If

            Return _returnValue
        End Function

        Private Shared __IsXmlSchemaValidEventErrorOccurred As System.Boolean = False
        Private Shared Sub __IsXmlSchemaValidEvent(ByVal _object As Sys.Object, ByVal _arguments As Xsd.ValidationEventArgs)
            If _arguments.Severity = Xsd.XmlSeverityType.Error Then
                __IsXmlSchemaValidEventErrorOccurred = True
            End If
        End Sub
        Friend Shared Function ___IsXmlSchemaValid(ByVal _objectName As System.String, ByVal _object() As System.Byte, ByVal _throwException As System.Boolean) As System.Boolean
            ___IsArrayEmptyNot("_object", _object, True)

            __IsXmlSchemaValidEventErrorOccurred = False
            Dim _stream As Iou.MemoryStream = New Iou.MemoryStream(_object)
            Try
                Xsd.XmlSchema.Read(_stream, New Xsd.ValidationEventHandler(AddressOf __IsXmlSchemaValidEvent))
            Catch
                __IsXmlSchemaValidEventErrorOccurred = True
            End Try
            _stream.Dispose()

            Dim _returnValue As System.Boolean = Not __IsXmlSchemaValidEventErrorOccurred

            If Not _returnValue And _throwException Then
                Throw New IsXmlSchemaValidNotException(_objectName, _object)
            End If

            Return _returnValue
        End Function

        Private Shared __IsXmlSchemaValidNotEventErrorOccurred As System.Boolean = False
        Private Shared Sub __IsXmlSchemaValidNotEvent(ByVal _object As Sys.Object, ByVal _arguments As Xsd.ValidationEventArgs)
            If _arguments.Severity = Xsd.XmlSeverityType.Error Then
                __IsXmlSchemaValidNotEventErrorOccurred = True
            End If
        End Sub
        Friend Shared Function ___IsXmlSchemaValidNot(ByVal _objectName As System.String, ByVal _object() As System.Byte, ByVal _throwException As System.Boolean) As System.Boolean
            ___IsArrayEmptyNot("_object", _object, True)

            __IsXmlSchemaValidNotEventErrorOccurred = False
            Dim _stream As Iou.MemoryStream = New Iou.MemoryStream(_object)
            Try
                Xsd.XmlSchema.Read(_stream, New Xsd.ValidationEventHandler(AddressOf __IsXmlSchemaValidNotEvent))
            Catch
                __IsXmlSchemaValidNotEventErrorOccurred = True
            End Try
            _stream.Dispose()

            Dim _returnValue As System.Boolean = __IsXmlSchemaValidNotEventErrorOccurred

            If Not _returnValue And _throwException Then
                Throw New IsXmlSchemaValidException(_objectName, _object)
            End If

            Return _returnValue
        End Function

        Private Shared __IsXmlValidEventErrorOccurred As System.Boolean = False
        Private Shared Sub __IsXmlValidEvent(ByVal _object As Sys.Object, ByVal _arguments As Xsd.ValidationEventArgs)
            If _arguments.Severity = Xsd.XmlSeverityType.Error Then
                __IsXmlValidEventErrorOccurred = True
            End If
        End Sub
        Friend Shared Function ___IsXmlValid(ByVal _objectName As System.String, ByVal _objectXml() As System.Byte, ByVal _objectXmlSchema() As System.Byte, ByVal _throwException As System.Boolean) As System.Boolean
            ___IsXmlWellFormed("_objectXml", _objectXml, True)
            ___IsXmlSchemaValid("_objectXmlSchema", _objectXmlSchema, True)

            Dim _stream As Iou.MemoryStream = New Iou.MemoryStream(_objectXml)
            Dim _xmlDocument As W3c.XmlDocument = New W3c.XmlDocument()
            _xmlDocument.Load(_stream)
            _stream.Dispose()

            _stream = New Iou.MemoryStream(_objectXmlSchema)
            Dim _xmlSchemaDocument As Xsd.XmlSchema = Xsd.XmlSchema.Read(_stream, Nothing)
            _stream.Dispose()

            __IsXmlValidEventErrorOccurred = False
            _xmlDocument.Schemas.Add(_xmlSchemaDocument)
            _xmlDocument.Validate(New Xsd.ValidationEventHandler(AddressOf __IsXmlValidEvent))

            Dim _returnValue As System.Boolean = Not __IsXmlValidEventErrorOccurred

            If Not _returnValue And _throwException Then
                Throw New IsXmlValidNotException(_objectName, _objectXml, _objectXmlSchema)
            End If

            Return _returnValue
        End Function

        Private Shared __IsXmlValidNotEventErrorOccurred As System.Boolean = False
        Private Shared Sub __IsXmlValidNotEvent(ByVal _object As Sys.Object, ByVal _arguments As Xsd.ValidationEventArgs)
            If _arguments.Severity = Xsd.XmlSeverityType.Error Then
                __IsXmlValidNotEventErrorOccurred = True
            End If
        End Sub
        Friend Shared Function ___IsXmlValidNot(ByVal _objectName As System.String, ByVal _objectXml() As System.Byte, ByVal _objectXmlSchema() As System.Byte, ByVal _throwException As System.Boolean) As System.Boolean
            ___IsXmlWellFormed("_objectXml", _objectXml, True)
            ___IsXmlSchemaValid("_objectXmlSchema", _objectXmlSchema, True)

            Dim _stream As Iou.MemoryStream = New Iou.MemoryStream(_objectXml)
            Dim _xmlDocument As W3c.XmlDocument = New W3c.XmlDocument()
            _xmlDocument.Load(_stream)
            _stream.Dispose()

            _stream = New Iou.MemoryStream(_objectXmlSchema)
            Dim _xmlSchemaDocument As Xsd.XmlSchema = Xsd.XmlSchema.Read(_stream, Nothing)
            _stream.Dispose()

            __IsXmlValidNotEventErrorOccurred = False
            _xmlDocument.Schemas.Add(_xmlSchemaDocument)
            _xmlDocument.Validate(New Xsd.ValidationEventHandler(AddressOf __IsXmlValidNotEvent))

            Dim _returnValue As System.Boolean = __IsXmlValidNotEventErrorOccurred

            If Not _returnValue And _throwException Then
                Throw New IsXmlValidException(_objectName, _objectXml, _objectXmlSchema)
            End If

            Return _returnValue
        End Function

        Friend Shared Function ___IsArrayEmpty(ByVal _objectName As System.String, ByVal _object As System.Array, ByVal _throwException As System.Boolean) As System.Boolean
            ___IsNullNot(_objectName, _object, True)

            Dim _returnValue As System.Boolean = _object.Length = 0

            If Not _returnValue And _throwException Then
                Throw New IsArrayEmptyNotException(_objectName, _object)
            End If

            Return _returnValue
        End Function

        Friend Shared Function ___IsArrayEmptyNot(ByVal _objectName As System.String, ByVal _object As System.Array, ByVal _throwException As System.Boolean) As System.Boolean
            ___IsNullNot(_objectName, _object, True)

            Dim _returnValue As System.Boolean = Not _object.Length = 0

            If Not _returnValue And _throwException Then
                Throw New IsArrayEmptyException(_objectName)
            End If

            Return _returnValue
        End Function

    End Class
End Namespace
